﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using FirstFloor.ModernUI.Windows.Controls;
using IsikFx.Project.ClientApp.Helpers;
using IsikFx.Project.CommonTypes.Announcement;
using IsikFx.Project.CommonTypes.CRUD;

namespace IsikFx.Project.ClientApp.Content
{
    /// <summary>
    /// Interaction logic for DeleteAnnouncement.xaml
    /// </summary>
    public partial class DeleteAnnouncement : UserControl
    {

        public DeleteAnnouncement()
        {
            InitializeComponent();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ModernDialog dialog = new ModernDialog();
            CrudResponseMessage response = new CrudResponseMessage();
            response = Helper.DeleteAnnouncement(((sender as Button).DataContext as ManipulatedItemSource).announcement.ID);
            if (response.HasError)
            {
                //HATA
                dialog.Content = "HATA";
            }
            else
            {
                dialog.Content = "Silme İşlemi Başarılı Bir Şekilde Gerçekleşti!!";
                dataAnnouncements.ItemsSource = GetItemSource();
            }
            dialog.ShowDialog();
        }

        private void dataAnnouncements_Loaded_1(object sender, RoutedEventArgs e)
        {


            dataAnnouncements.ItemsSource = GetItemSource();
        }

        private List<ManipulatedItemSource> GetItemSource()
        {
            List<ManipulatedItemSource> itemSource = new List<ManipulatedItemSource>();
            List<Announcement> announcements = new List<Announcement>();
            announcements = GetAnnonuncements();
            if (announcements == null || announcements.Count == 0)
                return new List<ManipulatedItemSource>();
            foreach (Announcement announcement in announcements)
            {
                ManipulatedItemSource item = new ManipulatedItemSource();
                item.announcement = announcement;
                item.personelType = announcement.RoleType == ((int)Helper.Roles.Sales) ? "Satış" : "Retention";
                itemSource.Add(item);
            }
            return itemSource;
        }

        private List<Announcement> GetAnnonuncements()
        {
            return Helpers.Helper.GetActiveAnnouncementsAsAdmin(Convert.ToInt32(Helpers.Helper.CurrentUser.UserID)).Response.AnnouncementArray;
        }

        public class ManipulatedItemSource
        {
            public Announcement announcement { get; set; }
            public string personelType { get; set; }
        }
    }
}
